<?php

class Front_Forms_Games extends Zend_Form {

    public function __construct($options = null) {
        parent::__construct($options);
    }

    protected $_element_decorator = array(
        'ViewHelper',
        'Description',
        'Errors',
        array('HtmlTag', array('tag' => 'div', 'class' => 'data-element')),
        array('Label', array('class' => 'label-item')),
        array(array('fe' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row-filter'))
    );

    public function init() {
        parent::init();
        $this->setAttrib('name', 'games_form');
        $this->setAttrib('class', 'games_form');
        $this->setMethod('GET');
        
        $this->initTournaments();
        $this->initSeasons();
        $this->initRounds();
        $this->initClubs();

        $this->addElement('submit', 'submit', array(
            'label' => 'Search',
            'decorators' => $this->_element_decorator
        ));
        $this->submit->removeDecorator('Label');
    }

    /*
     * Tournament
     */

    public function initTournaments() {
        $this->addElement('select', 'id_tour', array(
            'label' => 'Tournament',
            'decorators' => $this->_element_decorator,
            'multioptions' => array()
        ));
    }

    public function populateTournaments($tournaments) {
        if (!empty($tournaments)) {
            for ($index = 0; $index < count($tournaments); $index++) {
                $tournament = array(
                    $tournaments[$index]['id'] => $tournaments[$index]['name']
                );
                $this->id_tour->addMultiOptions($tournament);
            }
        }
    }

    /*
     * Seasons
     */

    public function initSeasons() {
        $this->addElement('select', 'season', array(
            'label' => 'Season',
            'decorators' => $this->_element_decorator,
            'multioptions' => array(0=>'--All--')
        ));
    }

    public function populateSeasons($seasons) {        
        if (!empty($seasons)) {
            for($index = 0; $index < count($seasons); $index++) {
                $season = array(
                  $seasons[$index]['season']    =>  $seasons[$index]['season']
                );
                $this->season->addMultiOptions($season);
            }
        }
    }
    
    /*
     * Rounds
     */
    public function initRounds() {
        $this->addElement('select', 'round', array(
            'label' => 'Round',
            'decorators' => $this->_element_decorator,
            'multioptions' => array(0=>'--All--')
        ));
    }
    public function populateRounds($rounds) {        
        if (!empty($rounds)) {
            for ($index = 0; $index < count($rounds); $index++) {
                $round = array(
                    $rounds[$index]['round'] => $rounds[$index]['round']
                );
                $this->round->addMultiOptions($round);
            }
        }
    }

    public function initClubs() {
        $this->addElement('select', 'id_club', array(
            'label' => 'Club',
            'decorators' => $this->_element_decorator,
            'multioptions' => array(0=>'--All--')
        ));
    }
    public function populateClubs($clubs) {
        if (!empty($clubs)) {
            for ($index = 0; $index < count($clubs); $index++) {
                $club = array(
                    $clubs[$index]['id_club'] => $clubs[$index]['club_name']
                );
                $this->id_club->addMultiOptions($club);
            }
        }
    }

}